package com.glory.cqaospda.adapter;


import android.graphics.Color;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.glory.cqaospda.R;
import com.glory.cqaospda.bean.MaintenanceBean;

import java.util.List;

import androidx.annotation.Nullable;

public class RepairAdapter extends BaseQuickAdapter<MaintenanceBean.ItemList, BaseViewHolder> {

    private List<MaintenanceBean.ItemList> datalist;
    private OnItemClickListener mOnItemClickListener;


    public RepairAdapter(@Nullable List<MaintenanceBean.ItemList> data) {
        super(R.layout.adapter_repair, data);
        datalist = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, MaintenanceBean.ItemList item) {

        helper.setText(R.id.tvUserName, item.getMUserName());
        helper.setText(R.id.tvLongTime, item.getMLongTime());
        helper.setText(R.id.tvEquipmentName, item.getMEquipmentName());
        String priority = "";
        if ("0".equals(item.getMPriority())){
            priority = "高";
        }
        if ("1".equals(item.getMPriority())){
            priority = "中";
        }
        if ("2".equals(item.getMPriority())){
            priority = "低";
        }
        helper.setText(R.id.tvPriority,priority);
        switch (item.getMRepairsType()){
            case "0":
                helper.setText(R.id.tvRepairsType, item.getMMaintenanceItem());
                break;
            case "1":
                helper.setText(R.id.tvRepairsType, "改机");
                break;
            case "2":
                helper.setText(R.id.tvRepairsType, "工程借机");
                break;
            case "3":
                helper.setText(R.id.tvRepairsType, "其他");
                break;
        }


        helper.setText(R.id.tvStart, "0".equals(item.getMMaintainType())?"接单":"维修");
        if ("0".equals(item.getMMaintainType())){
            helper.setBackgroundColor(R.id.tvStart, Color.parseColor("#00FF00"));
//            helper.setTextColor(R.id.tvStart, Color.parseColor("#00FF00"));
        }else {
            helper.setBackgroundColor(R.id.tvStart, Color.parseColor("#FF000000"));
//            helper.setTextColor(R.id.tvStart, Color.parseColor("#FF000000"));
        }
        helper.getView(R.id.tvStart).setOnClickListener(view -> {
            mOnItemClickListener.onItemClick(item,helper.getAdapterPosition());
        });

    }

    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(MaintenanceBean.ItemList itemList,int position);
    }

}
